$(function() {
	$("#left").load("../common/gover-left.html");
	var param = parseQueryString().param;
	var userId = sessionStorage.getItem("userId");
	var type = parseQueryString().type == null ? '1' : parseQueryString().type;
	$(".ystep1").loadStep({
		size: "small",
		color: "green",
		steps: [{
				title: "事项选择"
			},
			{
				title: "服务选择"
			},
			{
				title: "信息录入"
			},
			{
				title: "寄件选择"
			},
			{
				title: "取件选择"
			},
			{
				title: "提交成功"
			}
		]
	});
	$(".ystep1").setStep(5);
	my_vue = new Vue({
		el: '#vue_info',
		data: {
			address: {
				acceptName: '',
				phone: '',
				address: '',
				caddress: '',
				ctime: ''
			}
		},
		methods: {

			clientExitQueue: function() {
				window.location = "selfHelpFormInput.html";
			},
			changeOp: function() {
				window.location = "scannerIndex.html"
			},
			exitProcess: function(op) {
				if(op == 'index') {
					$.showConfirm({
						'title': '',
						'content': '是否退出办理？',
						"showClose": false,
						"sureLabel": "取消",
						"cancelLabel": "退出办理",
						'cancel': this.toIndex
					});
				} else if(op == 'scanner') {
					$.showConfirm({
						'title': '',
						'content': '是否退出办理？',
						"showClose": false,
						"sureLabel": "取消",
						"cancelLabel": "退出办理",
						'cancel': this.toScanner
					});
				}
			},
			toIndex: function() {
				window.location = "index.html"
			},
			toScanner: function() {
				window.location = "scannerIndex.html"
			},
			finish: function() {
				this.saveFetchWay();
			},
			lastStep: function() {
				window.location = "selfHelpChooseReceiveType.html?param=" + param;
			},
			exitAttendTo: function() {
				$.openDialog({
					'title': '',
					"showClose": false,
					'width': 824,
					'height': 460,
					'url': 'selfHelpExitChoose.html'
				});
			},
			saveFetchWay: function() {
				var data = "";
				if(type == '1') {
					data = this.address.acceptName + ";" + this.address.phone + ";" + this.address.address;
				}
				this.$http.post('http://192.168.10.45:8888/oc_tengzhou/gover/saveFetchWay.do', {
					userId: userId,
					fetchWay: type,
					date: data
				}, {
					emulateJSON: true
				}).then(function(result) {
					if(type=='1'){

						if(validateReName()==false||validateRePhone()==false||validateReAddress()==false){
							return false;
						}						
					}
					console.log(toJson(result.data));
					doMask();
					if(result.data.success) {
						unMask();
						window.location = "selfHelpFinish.html";
					} else {
						unMask();
						showRedMsg("message", "服务器正忙,请稍候重试");
						console.log(result.data.message);
					}
				}, function(result) {
					unMask();
					showRedMsg("message", "服务器正忙,请稍候重试");
					console.log('保存接口失败:' + toJson(result));
				})
			}
		},
		ready: function() {
			console.log(type);
			if(type == '1') {
				$("#type1").removeClass("dis_no")
			} else if(type == '2') {
				$("#type2").removeClass("dis_no")
			}
			console.log(param);
			this.address = toObj(decodeURI(param));
		}
	});
});